package ca.concordia.soen6461.wichf.dao.mem;

import ca.concordia.soen6461.wichf.dao.memdb.Table;
import ca.concordia.soen6461.wichf.dao.memdb.TableDefinition;
import ca.concordia.soen6461.wichf.entity.PatientCart;
import ca.concordia.soen6461.wichf.entity.ScheduledEvent;
import ca.concordia.soen6461.wichf.entity.User;

public class DB {

	public static final TableDefinition<PatientCart> patientCartDef = new TableDefinition<PatientCart>() {

		@Override
		public Class<? extends PatientCart> getType() {
			return PatientCart.class;
		}

		@Override
		public String primaryKey(PatientCart value) {
			return value.getPatient().getId();
		}
		
	};
	
	public static final Table<PatientCart> patientCartTable = new Table<PatientCart>(patientCartDef);
	
	public static final TableDefinition<ScheduledEvent> scheduledEventDef = new TableDefinition<ScheduledEvent>() {

		@Override
		public Class<? extends ScheduledEvent> getType() {
			return ScheduledEvent.class;
		}

		@Override
		public String primaryKey(ScheduledEvent value) {
			return value.getUser().getId() + "/" + value.getFrom();
		}
		
	};
	
	public static final Table<ScheduledEvent> scheduledEventTable = new Table<ScheduledEvent>(scheduledEventDef);
	
	public static final TableDefinition<User> userDef = new TableDefinition<User>() {

		@Override
		public Class<? extends User> getType() {
			return User.class;
		}

		@Override
		public String primaryKey(User value) {
			return value.getId();
		}
		
	};
	
	public static final Table<User> userTable = new Table<User>(userDef);
	
	public static final User patient = new User();
	public static final User anotherPatient = new User();
	public static final User doctor = new User();

	static {
		patient.setId("ABCD80122801");
		patient.setPassword("password");
		patient.setName("Mr. Smith");
		patient.getRoles().add(User.Role.PATIENT);
		userTable.save(patient);

		anotherPatient.setId("ABCD12345678");
		anotherPatient.setPassword("password");
		anotherPatient.setName("A");
		anotherPatient.getRoles().add(User.Role.PATIENT);
		userTable.save(anotherPatient);

		doctor.setId("DCTR61111111");
		doctor.setPassword("password");
		doctor.setName("Doctor");
		doctor.getRoles().add(User.Role.DOCTOR);
		userTable.save(doctor);
	}
	
}
